﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="html" indent="yes"/>

  <xsl:key name="tlist" match="TestList" use="@id"/>

  <xsl:template match="/" >

    <html>
      <head>
        <link type="text/css" rel="StyleSheet"  href="trx2html.css"   />
        <script language="javascript" type="text/javascript" src="trx2html.js"></script>
        <title>
          TRX Report -
          <xsl:value-of select="TestRun/TestSettings/Description"/>
        </title>

      </head>
      <body onload="summary();">
        <a name="__top" />

        <h3>
          TRX Report -
          <xsl:value-of select="TestRun/TestSettings/Description"/>
        </h3>

        <div class="contents">
          <a href="#totals">Totals</a>
          |
          <a href="#summary">Summary</a>
          |
          <a href="#detail">Detail</a>
          |
          <a href="#envInfo">Environment Information</a>
        </div>
        <br />

        <a name="totals" >
          <li>Totals</li>
        </a>
        <br />
        <input type="hidden" id="total">
          <xsl:attribute name="value">
            <xsl:value-of select="TestRun/ResultSummary/Counters/@total"/>
          </xsl:attribute>
        </input>
        <input type="hidden" id="passed">
          <xsl:attribute name="value">
            <xsl:value-of select="TestRun/ResultSummary/Counters/@passed"/>
          </xsl:attribute>
        </input>
        <input type="hidden" id="failed">
          <xsl:attribute name="value">
            <xsl:value-of select="TestRun/ResultSummary/Counters/@failed"/>
          </xsl:attribute>
        </input>
        <input type="hidden" id="aborted">
          <xsl:attribute name="value">
            <xsl:value-of select="TestRun/ResultSummary/Counters/@aborted"/>
          </xsl:attribute>
        </input>
        <input type="hidden" id="starttime">
          <xsl:attribute name="value">
            <xsl:value-of select="TestRun/Times/@start"/>
          </xsl:attribute>
        </input>
        <input type="hidden" id="endtime">
          <xsl:attribute name="value">
            <xsl:value-of select="TestRun/Times/@finish"/>
          </xsl:attribute>
        </input>

        <table id="tMainSummary"  border="0">
          <tr>
            <th>Percent</th>
            <th></th>
            <th>Status</th>
            <th>TotalTests</th>
            <th>Passed</th>
            <th>Failed</th>
            <th>Aborted</th>
            <th>Inconclusive</th>
            <th>TimeTaken</th>

            <th>Executed</th>
            <th>NotExecuted</th>
            <th>Disconnected</th>
            <th>Pending</th>
          </tr>
          <tr>
            <td id="percent"></td>

            <td id="barpercent" width="350px"  style="vertical-align:middle;font-size:200%"></td>
            <td  >
              <xsl:value-of select="TestRun/ResultSummary/@outcome"/>
            </td>
            <td  id="tdTotal" >
              <xsl:value-of select="TestRun/ResultSummary/Counters/@total"/>
            </td>

            <td  id="tdPassed">
              <xsl:value-of select="TestRun/ResultSummary/Counters/@passed"/>
            </td>

            <td  id="tdFailed">
              <xsl:value-of select="TestRun/ResultSummary/Counters/@failed"/>

            </td>

            <td  id="tdAborted">
              <xsl:value-of select="TestRun/ResultSummary/Counters/@aborted"/>

            </td>
            <td  id="tdInconclusive">
              <xsl:value-of select="TestRun/ResultSummary/Counters/@inconclusive"/>

            </td>
            <td id="tdtimetaken"></td>


            <td>
              <xsl:value-of select="TestRun/ResultSummary/Counters/@executed"/>

            </td>
            <td>
              <xsl:value-of select="TestRun/ResultSummary/Counters/@notExecuted"/>

            </td>
            <td>
              <xsl:value-of select="TestRun/ResultSummary/Counters/@disconnected"/>

            </td>
            <td>
              <xsl:value-of select="TestRun/ResultSummary/Counters/@pending"/>

            </td>
          </tr>
        </table>


        <br />

        <a name="summary" >
          <li>Test Class Summary</li>
        </a>
        <br />
        <table id="tSummaryDetail"  border="0">
          <tr>
            <th>Test Classes</th>
            <th>Status</th>
            <th>computerName</th>
            <th>Duration</th>
          </tr>
          <xsl:for-each select="TestRun/Results/WebTestResult">
            <tr>
              <td>
                <a>
                  <xsl:value-of select="@testName" />
                </a>
              </td>

              <!-- status -->
              <td width="80px">
                <xsl:value-of select="@outcome" />
              </td>

              <td>
                <xsl:value-of select="@computerName" />
              </td>

              <!-- Duration -->
              <td>
                <xsl:value-of select="@duration" />
              </td>
            </tr>
          </xsl:for-each>

          <xsl:for-each select="TestRun/Results/LoadTestResult">
            <tr>
              <td>
                <a>
                  <xsl:value-of select="@testName" />
                </a>
              </td>

              <!-- status -->
              <td width="80px">
                <xsl:value-of select="@outcome" />
              </td>

              <td>
                <xsl:value-of select="@computerName" />
              </td>

              <!-- Duration -->
              <td>
                <xsl:value-of select="@duration" />
              </td>
            </tr>
          </xsl:for-each>

        </table>



        <br />


        <a name="detail" >
          <li>Test Class Detail</li>
        </a>

        <br />

        <xsl:call-template name="tDetails" />
        <br />
        <br />

        <a name="detailinfo" >
          <li>Test Class Information</li>
        </a>

        <br />

        <xsl:call-template name="tTestDefinitions" />
        <br />
        <br />
        <a href="#__top">Back to top</a>
        <br />
        <br />
        <a name="envInfo" />
        <xsl:call-template name="envInfo" />
        <hr style="border-style:dotted;color:#dcdcdc"/>
        <i style="width:100%;font:10pt Verdana;text-align:center;background-color:#dcdcdc">
          <!--The VSTS Test Results HTML Viewer. (c) <a href="http://blogs.msdn.com/rido">rido</a>'08-->
        </i>

      </body>
    </html>
  </xsl:template>


  <xsl:template name="envInfo">
    <table>
      <tr>
        <th colspan="2">TestRun Environment Information</th>
      </tr>

      <tr>
        <th align="right">MachineName</th>
        <td>
          <xsl:value-of select="TestRun/Results/WebTestResult/@computerName"/>
        </td>
      </tr>
      <tr>
        <th align="right">UserName</th>
        <td>
          <xsl:value-of select="TestRun/@runUser"/>
        </td>
      </tr>
      <tr>
        <th align="right">Original TRXFile</th>
        <td>
          <xsl:value-of select="TestRun/@name"/>
        </td>
      </tr>
    </table>

  </xsl:template>

  <xsl:template name="tDetails">

    <xsl:for-each select="TestRun/Results/LoadTestResult">
      <div style="margin-left:30px;">
        <b>
          <u>
            Test Name : <xsl:value-of select="@testName" />
          </u>
        </b>
        <br/>
        <br/>
        <table>
          <th>Computer Name</th>
          <th>Run Status</th>
          <th>Duration</th>
          <th>Status</th>
          <tr>


            <!-- computername -->
            <td>
              <xsl:value-of select="@computerName" />
            </td>

            <!-- Duration -->
            <td>
              <xsl:value-of select="@runStatus" />
            </td>

            <!-- run -->
            <td>
              <xsl:value-of select="@duration" />
            </td>

            <!-- status -->
            <xsl:choose>
              <xsl:when test="@outcome='Failed'">
                <td class="testKo" width="80px">
                  <xsl:value-of select="@outcome" />
                </td>
              </xsl:when>
              <xsl:when test="@outcome='Passed'">
                <td class="testOk" width="80px">
                  <xsl:value-of select="@outcome" />
                </td>
              </xsl:when>
              <xsl:otherwise>
                <td class="testIgnore" width="80px">
                  <xsl:value-of select="@outcome" />
                </td>
              </xsl:otherwise>
            </xsl:choose>
          </tr>
        </table>

        <table id="intbl" >
          <th>Percent</th>
          <th></th>
          <th>Scenario Name</th>
          <th>Test Name</th>
          <th>Duration</th>
          <th>Total Tests</th>
          <th>Tests Passed</th>
          <th>Tests Failed</th>
          <th>Tests Aborted</th>
          <xsl:for-each select="Summary/TestSummaries/TestSummary">

            <tr>
              <td  width="50px"  id="dpercent"></td>

              <td id="dbarpercent" width="150px"  style="vertical-align:middle;">

              </td>

              <!-- sname -->
              <td width="150px">
                <xsl:value-of select="@scenarioName" />
              </td>

              <!-- testname -->
              <td>
                <xsl:value-of select="@testName" />
              </td>

              <!-- averageDuration -->
              <td width="50px">
                <xsl:value-of select="@averageDuration" />
              </td>

              <td width="30px">

                <xsl:choose>
                  <xsl:when test="@totalTests >= 0">
                    <xsl:value-of select="@totalTests" />
                  </xsl:when>
                  <xsl:otherwise>
                    0
                  </xsl:otherwise>
                </xsl:choose>
              </td>

              <td width="30px">
                <xsl:choose>
                  <xsl:when test="@testsPassed >= 0">
                    <xsl:value-of select="@testsPassed" />
                  </xsl:when>
                  <xsl:otherwise>
                    0
                  </xsl:otherwise>
                </xsl:choose>
              </td>

              <td width="30px">

                <xsl:choose>
                  <xsl:when test="@testsFailed >= 0">
                    <xsl:value-of select="@testsFailed" />
                  </xsl:when>
                  <xsl:otherwise>
                    0
                  </xsl:otherwise>
                </xsl:choose>
              </td>

              <td width="30px">
                <xsl:choose>
                  <xsl:when test="@testsAborted >= 0">
                    <xsl:value-of select="@testsAborted" />
                  </xsl:when>
                  <xsl:otherwise>
                    0
                  </xsl:otherwise>
                </xsl:choose>
              </td>
            </tr>


          </xsl:for-each>

        </table>
        <script>
          CalculateDetailsPercent();
        </script>
      </div>
    </xsl:for-each>
  </xsl:template>



  <xsl:template name="tTestDefinitions">

    <xsl:for-each select="TestRun/TestDefinitions/LoadTest">
      
      <div style="margin-left:20px;">
        <style>
          b {
          font: bold italic 14px "Times New Roman", "MS Serif", "New York", serif;
          margin: 0;
          padding: 0;
          color: #38ABD1;
          }
        </style>

        <b>
          <u>
            Test Name : <xsl:value-of select="@Name" />
          </u>
        </b>

       
        <br/>


        <xsl:for-each select="Scenarios/Scenario">
          <br/>
          <div style="margin-left:20px;">

            <b>
              Scenario Name : <xsl:value-of select="@Name" />
            </b>
           
            <br/>
            <xsl:for-each select="ThinkProfile">

              <div style="margin-left:20px;">
                <b>
                  Think Profile
                </b>
                <div style="margin-left:20px;">
                  <table>
                    <th>
                      Value
                    </th>
                    <th>
                      Pattern
                    </th>
                    <tr>
                      <td>
                        <xsl:value-of select="@Value"/>
                      </td>
                      <td>
                        <xsl:value-of select="@Pattern"/>
                      </td>
                    </tr>
                  </table>
                </div>
              </div>
            </xsl:for-each>

        
            <br/>
            <xsl:for-each select="TestMix">
              <div style="margin-left:20px;">
                <b>
                  Test Mix
                </b>
                <xsl:for-each select="TestProfile">
                  <div style="margin-left:20px;">
                    <table>

                      <tr>
                        <td>
                          <xsl:value-of select="@Name"/>
                        </td>
                      </tr>
                    </table>
                  </div>
                </xsl:for-each>
              </div>
            </xsl:for-each>

           
            <br/>
            <xsl:for-each select="BrowserMix">
              <div style="margin-left:20px;">
                <b>
                  Browser Mix
                </b>
                <xsl:for-each select="BrowserProfile">
                  <div style="margin-left:20px;">
                    <b>
                      Browser Profile :  Percentage = <xsl:value-of select="@Percentage"/>
                    </b>
                    <table>
                      <xsl:for-each select="Browser">
                        <th>
                          Name
                        </th>
                        <th>
                          Max Connections
                        </th>
                        <tr>
                          <td>
                            <xsl:value-of select="@Name"/>
                          </td>
                          <td>
                            <xsl:value-of select="@MaxConnections"/>
                          </td>
                        </tr>
                      </xsl:for-each>
                    </table>
                  </div>
                </xsl:for-each>
              </div>
            </xsl:for-each>

          
            <br/>
            <xsl:for-each select="NetworkMix">
              <div style="margin-left:20px;">
                <b>
                  Network Mix
                </b>
                <xsl:for-each select="NetworkProfile">
                  <div style="margin-left:20px;">
                    <b>
                      Network Profile :  Percentage = <xsl:value-of select="@Percentage"/>
                    </b>
                    <table>
                      <xsl:for-each select="Network">
                        <th>
                          Name
                        </th>
                        <th>
                          BandwidthInKbps
                        </th>

                        <tr>
                          <td>
                            <xsl:value-of select="@Name"/>
                          </td>
                          <td>
                            <xsl:value-of select="@BandwidthInKbps"/>
                          </td>
                        </tr>
                      </xsl:for-each>
                    </table>
                  </div>
                </xsl:for-each>
              </div>
            </xsl:for-each>

          </div>

        </xsl:for-each>


       
        <br/>
      </div>
      <div>
        <xsl:for-each select="RunConfigurations/RunConfiguration">
          <div style="margin-left:20px;">
            <b>
              Run Configuration :
            </b>
            <table>

              <th>
                Name
              </th>
              <th>
                Description
              </th>

              <th>
                ResultsStoreType
              </th>
              <th>
                TimingDetailsStorage
              </th>
              <th>
                WebTestConnectionPoolSize
              </th>
              <th>
                MaxThresholdViolations
              </th>
              <th>
                MaxRequestUrlsReported
              </th>
              <th>
                WebTestConnectionModel
              </th>

              <tr>
                <td>
                  <xsl:value-of select="@Name"/>
                </td>
                <td>
                  <xsl:value-of select="@Description"/>
                </td>
                <td>
                  <xsl:value-of select="@ResultsStoreType"/>
                </td>
                <td>
                  <xsl:value-of select="@TimingDetailsStorage"/>
                </td>
                <td>
                  <xsl:value-of select="@WebTestConnectionPoolSize"/>
                </td>
                <td>
                  <xsl:value-of select="@MaxThresholdViolations"/>
                </td>
                <td>
                  <xsl:value-of select="@MaxRequestUrlsReported"/>
                </td>
                <td>
                  <xsl:value-of select="@WebTestConnectionModel"/>
                </td>
              </tr>

            </table>
          </div>
        </xsl:for-each>


      </div>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
